﻿using System.Collections.Generic;
using HardMock.Domain;
using HardMock.Recording;
using Rhino.Mocks;
using Xunit;

namespace Tests
{
    public class InMemoryRepositoryTest
    {
        private readonly MockRepository mockRepository;
        private readonly ISerializer serializerMock;
        private readonly IRepository target;

        public InMemoryRepositoryTest()
        {
            mockRepository = new MockRepository();
            serializerMock = mockRepository.StrictMock<ISerializer>();
            serializerMock.Expect(x => x.Deserialize(null))
                          .IgnoreArguments()
                          .Return(new Dictionary<string, CallResult>());
            mockRepository.ReplayAll();
            target = new InMemoryRepository(serializerMock);
        }

        [Fact]
        public void Should_not_found_from_repository()
        {
            bool succeed;
            target.TryGet("pouet", out succeed);

            Assert.False(succeed);
        }

        [Fact]
        public void Should_update_from_repository()
        {
            bool succeed;
            var expected = new CallResult(null, null);
            target.Update("pouet", expected);

            var actual = target.TryGet("pouet", out succeed);

            Assert.True(succeed);
            Assert.Equal(expected, actual);
        }

        [Fact]
        public void Should_serialize_repository()
        {
            serializerMock.Expect(x => x.Serialize(null, null)).IgnoreArguments();
            mockRepository.ReplayAll();
            target.Serialize(null);
        }
    }
}